﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ascent.Module.BusinessObjects.Sales
{
    public partial class SaleOrderDetail
    {
        protected override void OnChanged(string propertyName, object oldValue, object newValue)
        {
            base.OnChanged(propertyName, oldValue, newValue);
            TotalAmount = (UnitPrice * Quantity);
            DiscountAmount = TotalAmount * DiscountPercent / 100;
            Amount = TotalAmount - DiscountAmount;
        }

        protected override void OnSaved()
        {
            base.OnSaved();
            float detailAomout=0f;
            foreach (var detail in this.SaleOrder.SaleOrderDetails)
            {
                detailAomout += detail.TotalAmount;
                
            }
            this.SaleOrder.TotalAmount = detailAomout;
 
        }
    }
}
